import {ORDER_LIST} from '../actions/actionType.js'

const initialState = {
  lists: []
}

const getOrderList = (state, action) => {
  if(action.currentPage === 0){
    let lists = action.obj.data.digestlist
    return {...state, lists}
  }else{
    let lists = state.lists
    let newlists = action.obj.data.digestlist
    return {...state, lists: lists.concat(newlists)}
  }
  
}

const orderListReducer = (state = initialState, action) => {
  switch(action.type){
    case ORDER_LIST:
      return getOrderList(state, action)
    default:
      return state
  }
}

export default orderListReducer